package com.park.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.park.dao.RechargerecordMapper;
import com.park.model.Park;
import com.park.model.PosChargeData;
import com.park.model.Rechargerecord;
import com.park.service.ParkService;
import com.park.service.RechargeRecordService;
@Service
public class RechargeRecordServiceImpl implements RechargeRecordService {

	@Autowired
	RechargerecordMapper rechargeRecordDao;
	
	@Autowired
	ParkService parkService;
	
	@Override
	public int deleteByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return rechargeRecordDao.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(Rechargerecord record) {
		// TODO Auto-generated method stub
		return rechargeRecordDao.insert(record);
	}

	@Override
	public int insertSelective(Rechargerecord record) {
		// TODO Auto-generated method stub
		return rechargeRecordDao.insertSelective(record);
	}

	@Override
	public Rechargerecord selectByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return rechargeRecordDao.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(Rechargerecord record) {
		// TODO Auto-generated method stub
		return rechargeRecordDao.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(Rechargerecord record) {
		// TODO Auto-generated method stub
		return rechargeRecordDao.updateByPrimaryKey(record);
	}
	
	@Override
	public List<Rechargerecord> getPageByParkId(int parkId, int start, int count) {
		// TODO Auto-generated method stub
		return rechargeRecordDao.getPageByParkId(parkId, start, count);
	}

	@Override
	public List<Rechargerecord> getByParkAuthority(String userName) {
		// TODO Auto-generated method stub
		List<Park> parkList = parkService.getParks();
		if (userName != null)
			parkList = parkService.filterPark(parkList, userName);
		int num = 120 / parkList.size();
		if (num < 1) {
			num = 2;
		}
		List<Rechargerecord> rechargerecords = new ArrayList<Rechargerecord>();
		for (Park park : parkList) {
			List<Rechargerecord> tmRechargerecords = getPageByParkId(park.getId(), 0, num);
			System.out.println("打印--------------"+tmRechargerecords);
			rechargerecords.addAll(tmRechargerecords);
		}
		return rechargerecords;
	}

	@Override
	public List<Rechargerecord> getBySearchRechargeParkId(Integer parkId, String parkDesc, String plateNumber,
			String phoneNumber, String name) {
		// TODO Auto-generated method stub
		return rechargeRecordDao.getBySearchRechargeParkId(parkId, plateNumber, parkDesc, phoneNumber, name);
	}

	@Override
	public List<Rechargerecord> getBySearchRecharge(String parkDesc, String plateNumber, String phoneNumber,
			String name) {
		// TODO Auto-generated method stub
		return rechargeRecordDao.getBySearchRecharge(plateNumber, parkDesc, phoneNumber, name);
	}

}
